const app = require('express')();
const server = require('http').Server(app);
const io = require('socket.io')(server);


//设置端口9093
server.listen(9093);


//创建socket.io连接
io.on('connection', function (socket) {
  //获取messages事件
  socket.on('messages', function (data) {
    //向所有连接进行广播
    socket.broadcast.emit('messages', data)
    //对发出者进行广播，用户名加上我
    data.user=data.user+'[我]'
    socket.emit('messages', data)
  });
});

